package com.koala.learn.anno;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @author yantingrui
 * @date 2022/2/15   9:55
 */


public class Start {

    public static void main(String[] args) throws ClassNotFoundException {
        try {
            Class c = Class.forName("com.koala.learn.anno.Student");// 获取类

            // 获得类的单个注解
            MyTable tb = (MyTable) c.getAnnotation(MyTable.class);
            System.out.println(tb);

            // 获得类的所有注解
            Annotation[] annotations = c.getAnnotations();
            for (Annotation a : annotations) {
                System.out.println(a);
            }

            // 获得类的属性注解
            Field f = c.getDeclaredField("stuName");// 获取属性
            MyField myField = f.getAnnotation(MyField.class);// 获取属性的注解
            System.out.println(myField.columnName() + " " + myField.type() + " " + myField.length());

            // 根据获得的表明、字段信息拼出DDL语句，使用JDBC执行这个SQL，在数据库中生成相关的表(省略)
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     *
     */
    @Test
    public void test44() {

    }

}
